package com.explorati.design_pattern.creational.singleton;

import java.util.HashMap;
import java.util.Map;

import com.mysql.jdbc.StringUtils;

/**
 * 容器(哈希Map)单例模式
 * 
 * @author explorati
 *
 */
public class ContainerSingleton {

	private ContainerSingleton() {

	}

	private static Map<String, Object> singletonMap = new HashMap<>();

	public static void putInstance(String key, Object instance) {
		if (!StringUtils.isNullOrEmpty(key) && instance != null) {
			if (!singletonMap.containsKey(key)) {
				singletonMap.put(key, instance);
			}
		}
	}

	public static Object getInstance(String key) {
		return singletonMap.get(key);
	}
}
